package com.asset.pojo;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Collection;
import java.util.List;

/**
 * @author 11725
 * 用户信息
 */
@Data
@Table(name = "tab_user")
public class User implements UserDetails {

    /** 账户未激活 */
    private static final Integer ACCOUNT_NOT_ACTIVATED = -1;
    /** 账户已启用 */
    private static final Integer ACCOUNT_ENABLE = 0;
    /** 账户已禁用 */
    private static final Integer ACCOUNT_DISABLED = 1;

    /** 用户编号 */
    @Id
    @KeySql(useGeneratedKeys = true)
    @Column(name = "uid")
    private Long id;

    /** 用户名 */
    private String username;

    /** 密码 */
    private String password;

    /** 账户状态 */
    @Column(name = "use_state")
    private Integer status;

    /** 姓名 */
    private String name;

    /** 部门编号 */
    private Long depaId;

    /** 性别 */
    private Integer gender;

    /** 手机号 */
    private String phone;

    /** MD5加密盐 */
    private String salt;

    private List<GrantedAuthority> roleList;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return roleList;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return ACCOUNT_ENABLE.equals(this.status);
    }
}
